import time
import unittest

from selenium.webdriver.common.by import By

from Page.Boss import Boss
from selenium import webdriver

from Tools.Tools import Tools


class BossCase(unittest.TestCase):
    @classmethod
    def setUpClass(cls):
        cls.logger = Tools().get_logger("Test.Boss")
    # 测试固件
    def setUp(self):
        self.logger.info('测试开始')
        self.driver = webdriver.Edge()
        self.driver.maximize_window()
        self.po = Boss(self.driver)


    def tearDown(self):
        self.logger.info('测试结束')
        time.sleep(3)
        self.driver.quit()
    # @unittest.skip
    def test_Boss_01_account_manage(self):
        try:
            self.logger.info('用例：验证账户管理入口')
            self.po.login()
            dy_login = self.po.find_element((By.XPATH,'/html/body/div[1]/div[3]/div/div[2]/div/div/p[1]/span')).text
            # 登录成功断言
            self.assertEqual('龙果支付后台',dy_login)
            # 点击账户管理
            self.po.account_manage()
            # 断言账户信息和账户历史信息
            dy2 = self.po.find_element((By.XPATH,'/html/body/div[1]/div[2]/div[2]/div[2]/div[4]/ul/li[1]/div/a')).text
            self.assertEqual('账户信息',dy2)
            dy3 = self.po.find_element((By.XPATH,'/html/body/div[1]/div[2]/div[2]/div[2]/div[4]/ul/li[2]/div/a')).text
            self.assertEqual('账户历史信息',dy3)
            self.logger.debug(f'断言账户管理入口：{dy2},{dy3}')
            self.logger.info('结果：成功进入账户管理入口')
        except Exception as e:
            self.logger.error(e)


    # 关闭账户管理
    @unittest.skip
    def test_Boss_02_account_manage(self):
        self.po.login()
        self.po.close_account_manage()

    def test_Boss_03_payment_manage(self):
        try:
            self.logger.info('用例：验证支付管理入口')
            self.po.login()
            dy_login = self.po.find_element((By.XPATH,'/html/body/div[1]/div[3]/div/div[2]/div/div/p[1]/span')).text
            # 登录成功断言
            self.assertEqual('龙果支付后台',dy_login)
            # 点击支付管理
            self.po.show_pay_manage()
            # 断言支付产品信息和用户支付配置
            dy2 = self.po.find_element((By.XPATH,'/html/body/div[1]/div[2]/div[2]/div[2]/div[8]/ul/li[1]/div/a')).text
            self.assertEqual('支付产品信息',dy2)
            dy3 = self.po.find_element((By.XPATH,'/html/body/div[1]/div[2]/div[2]/div[2]/div[8]/ul/li[2]/div/a')).text
            self.assertEqual('用户支付配置',dy3)
            self.logger.debug(f'断言支付管理入口：{dy2},{dy3}')
            self.logger.info('结果：成功进入支付管理入口')
        except Exception as e:
            self.logger.error(e)

if __name__ == '__main__':
    unittest.main()
